#!/usr/bin/php
<?php
	function __autoload ($ClassName) {
		require_once ("Classes/$ClassName.php");
	}
	function Report ($Level, $Message, $FName, $LineNo) {
		$Levels = array (
			'E_ERROR', 'E_WARNING', 'E_PARSE', 'E_NOTICE',
			'E_CORE_ERROR', 'E_CORE_WARNING',
			'E_COMPILE_ERROR', 'E_COMPILE_WARNING',
			'E_USER_ERROR', 'E_USER_WARNING', 'E_USER_NOTICE',
			'E_STRICT', 'E_RECOVERABLE_ERROR', 'E_DEPRECATED', 'E_USER_DEPRECATED',
		);
		$Fatal = in_array ($Level, array (1, 4, 16, 64, 256, 4096));
		$Level = $Levels [log ($Level, 2)];
#		$SourceLine = (array_key_exists ('Source', $GLOBALS) and $GLOBALS ['Source'] instanceof HeatherSource) ? $GLOBALS ['Source']->CurrentLine () : 'n/a';
		$SourceLine = (array_key_exists ('StringNo', $GLOBALS)) ? $GLOBALS ['StringNo'] + 1 : 'n/a';
		$String = "($FName:$LineNo) $Level at source line $SourceLine: $Message.\n";
		fwrite (STDERR, $String);
		if ($Fatal) die ();
	}
	set_error_handler ('Report');

#	$Source = new HeatherSource (file_get_contents ('php://stdin'));
#	while (NULL !== ($Line = $Source->NextLine ())) $Document->PushLine ($Line);

	$Document = new HeatherDocument ();
	$Strings = explode ("\n", str_replace ("\r\n", "\n", file_get_contents ('php://stdin')));
	foreach ($Strings as $StringNo => $String) $Document->AddString ($String);

#	var_dump ($Document->Render ());
#	echo (serialize ($Document->Render ()));
	echo ('<?xml version="1.0" encoding="utf-8"?>');
	echo ($Document->XMLRender ());
	echo ("\n");
?>